<?php
/* SVN FILE: $Id$ */
/**
 * Travian Alliance Coordinator
 * Copyright (c) 2009, Travian Alliance Coordinator Team.
 *
 * This file is part of Travian Alliance Coordinator.
 *
 * Travian Alliance Coordinator is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Travian Alliance Coordinator is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * Travian Alliance Coordinator.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author $Author$
 * @copyright Copyright (c) 2009, Travian Alliance Coordinator Team.
 * @version $Revision$
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3
 */

class TravianHelper extends Helper {

    var $helpers = array('Html');

    /**
     * Returns a string of a tribe id
     * @param $tid tribe id, integer from 1 to 5
     */
    function tid2str($tid) {
        switch ($tid) {
            case 1:
                return __('Roman', true);
                break;
            case 2:
                return __('Teuton', true);
                break;
            case 3:
                return __('Gaul', true);
                break;
            case 4:
                return __('Natar', true);
                break;
            case 5:
                return __('Nature', true);
                break;
            default:
                return __('Unknown', true);
                break;
        }
    }

    /**
     * Creates an image similar to the one on the alliance page in travian,
     * showing how long ago the player was online.
     */
    function accessed($datetime) {
        $timepassed = time() - strtotime($datetime);

        // blue dot?

        if($timepassed < strtotime("+1 day")) {
            // green dot
            return $this->Html->image('active/green.gif', array('alt' => __('Last 24 hours', true), 'title' => __('Last 24 hours', true)));
        }
        if($timepassed < strtotime("+3 day")) {
            // yellow dot
            return $this->Html->image('active/yellow.gif', array('alt' => __('Last 3 days', true), 'title' => __('Last 3 days', true)));
        }
        if($timepassed < strtotime("+1 week")) {
            // red dot
            return $this->Html->image('active/red.gif', array('alt' => __('Last 7 days', true), 'title' => __('Last 7 days', true)));
        }
        // grey dot
        return $this->Html->image('active/grey.gif', array('alt' => __('More than 7 days', true), 'title' => __('More than 7 days', true)));
    }

}

?>